
import { mapState, mapMutations } from 'vuex'
import moment from 'moment'
export default {
  data () {
    return {
    }
  },
  computed: {
    ...mapState({
      defaultStep: state => state.app.defaultStep
    })
  },
  methods: {
    ...mapMutations('positionDetail', ['SET_CANDIDATE_LIST']),
    // 候选人状态
    transitionfeedbackResult (feedbackResult) {
      if (this.$i18n.locale === 'zh') {
        if (feedbackResult === 'NOSHOW') {
          return '候选人未到场'
        } else if (feedbackResult === 'OLD') {
          return '待定'
        } else if (feedbackResult === 'REFUSE') {
          return '拒绝'
        } else if (feedbackResult === 'NEXT') {
          return '同意进入下一轮'
        } else {
          return '未反馈'
        }
      } else {
        if (feedbackResult === 'NOSHOW') {
          return 'Absent'
        } else if (feedbackResult === 'OLD') {
          return 'To be decided'
        } else if (feedbackResult === 'REFUSE') {
          return 'Reject'
        } else if (feedbackResult === 'NEXT') {
          return 'Pass'
        } else {
          return '未反馈'
        }
      }
    },
    // 面试反馈num
    hasResultLength (interviewers) {
      let hasFeedBackCount = interviewers.length
      for (var i = 0; i < interviewers.length; i++) {
        if (interviewers[i].feedbackResult === '') {
          hasFeedBackCount = hasFeedBackCount - 1
        }
      }
      return hasFeedBackCount
    },
    // 候选人是否接受面试
    transitionCandidateAccepted (candidateStatus) {
      if (this.$i18n.locale === 'zh') {
        if (candidateStatus === 'pending') {
          return '待确认'
        } else if (candidateStatus === 'refuse') {
          return '已拒绝'
        } else if (candidateStatus === 'noShow') {
          return '未到场'
        }
      } else {
        return candidateStatus
      }
    },
    // 面试状态
    interviewStatus (status) {
      if (this.$i18n.locale === 'zh') {
        if (status === 'pending') {
          return '待确认'
        } else if (status === 'accepted') {
          return '已接受'
        } else if (status === 'refuse') {
          return '已拒绝'
        } else if (status === 'feedback') {
          return '已反馈'
        }
      } else {
        return status
      }
    },
    // 面试类型
    transitionInterviewType (type) {
      if (this.$i18n.locale === 'zh') {
        if (type === 'onSite') {
          return '现场面试'
        }
        if (type === 'phone') {
          return '电话面试'
        }
        if (type === 'video') {
          return '视频面试'
        }
      } else {
        return type
      }
    },
    // 修改面试按钮显示或者隐藏
    reArrangeInterviewBtn (record) {
      const arr = record.interviewer_array.map(item => {
        return item.feedbackResult
      })
      for (var i = 0; i < arr.length; i++) {
        if (arr[i] && arr[i] !== 'REFUSE') {
          return false
        }
      }
      return true
    },
    // 取消面试按钮显示或者隐藏
    cancelInterviewBtn (record) {
      if (record.valid === 'N') {
        return false
      } else {
        return true
      }
    },
    // 面试状态显示--面试已取消，，不显示长度
    isStateCancel (record, length) {
      const state = record.interviewStatus
      if (state === '面试已取消' || length === 0) {
        return false
      } else {
        return true
      }
    },
    // 面试评价表选题目类型
    questionType (value) {
      if (value === 'singleSelect' || value === 'scoreSelect') {
        return true
      } else {
        return false
      }
    },
    // 距离面试开始的时间
    timeInterval (time) {
      const startDate = moment(moment().format('YYYY-MM-DD HH:mm:ss'), 'YYYY-MM-DD HH:mm:ss')
      const endDate = moment(time, 'YYYY-MM-DD HH:mm:ss')
      // 秒
      const seconds = endDate.diff(startDate, 'seconds')
      // 分钟
      const mintus = (seconds / 60)
      return mintus
    },
    isShowCancelInterview (status) {
      if (status === 'someFeedback' || status === 'feedback' || status === 'expired' || status === 'canceled') {
        return false
      } else {
        return true
      }
    },
    // 面试列表去重
    interviewRepeat (interviewList) {
      const arr = [interviewList[0]]
      const list = interviewList
      var flag1 = true
      for (var i = 0; i < list.length; i++) {
        flag1 = true
        for (var j = 0; j < arr.length; j++) {
          if (list[i].application.id === arr[j].application.id && list[i].position.id === arr[j].position.id) {
            flag1 = false
          }
        }
        if (flag1 === true) {
          arr.push(list[i])
        }
      }
      const newArr = arr.map(item => {
        return {
          applicationId: item.application.id,
          positionId: item.position.id
        }
      })
      this.SET_CANDIDATE_LIST({ resumes: newArr })
    },
    formatDuration (durartion) {
      const lang = this.$i18n.locale
      let suffix = ''
      if (lang === 'zh') {
        if (durartion < 1) {
          suffix = ' 分钟'
          return durartion * 60 + suffix
        } else {
          suffix = ' 小时'
          return durartion + suffix
        }
      } else if (lang === 'en') {
        if (durartion < 1) {
          suffix = ' minutes'
          return durartion * 60 + suffix
        } else if (durartion > 1) {
          suffix = ' hours'
          return durartion + suffix
        } else {
          suffix = ' hour'
          return durartion + suffix
        }
      }
    },
    formatGender (gender) {
      const lang = this.$i18n.locale
      if (lang === 'zh') {
        return gender
      } else if (lang === 'en') {
        if (gender === '男') {
          return 'Men'
        } else if (gender === '女') {
          return 'Women'
        }
        return ''
      }
    },
    formatAge (age) {
      const lang = this.$i18n.locale
      if (!age) {
        return ''
      }
      if (lang === 'zh') {
        return age + '岁'
      } else if (lang === 'en') {
        return age + 'years old'
      }
    }
  }
}
